package org.lora.core;

import java.io.File;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.lora.core.context.WebContextFactory;

/**
 * <p>
 * Title:WebContextLoaderListener
 * </p>
 * <p>
 * Desription:初始化WebContext监听器
 * </p>
 * Create Time:2016年7月5日 下午6:54:32
 * 
 * @author Bladnir@outlook.com
 *         <p>
 *         History:
 *         </p>
 *         2016年7月5日 Bladnir Create</br>
 */
public class WebContextLoaderListener implements ServletContextListener {

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.
	 * ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {

		// just do nothing
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * javax.servlet.ServletContextListener#contextInitialized(javax.servlet
	 * .ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent event) {
		ServletContext servletContext = event.getServletContext();
		String webInf = servletContext.getRealPath("");
		String webContextConfigLocation = servletContext.getInitParameter("WebContextConfigLocation");
		webContextConfigLocation = webContextConfigLocation.replace("/", File.separator);
		WebContextFactory factory = new WebContextFactory(webInf + webContextConfigLocation);
		factory.creatWebContext();
	}
}